import Api from './api';

export async function getVerificationCode({ state, commit }, params) {
    let { data } = await this.$axios.post(Api.getVerificationRegcode, params);
    commit('SET_VERIFICA_CODEIMG', data);
}
export async function userReg({ state, commit }, params) {
    return await this.$axios.post(Api.userReg, params);
}
export async function userLogin({ state, commit }, params) {
    return await this.$axios.post(Api.userLogin, params);
}
export async function userLoginOut({ state, commit }, params) {
    return await this.$axios.post(Api.userLoginOut);
}
export async function nuxtServerInit({ commit }, { req }) {
    console.log(req.ctx.session)
    if (req.ctx.session && req.ctx.session.userInfo) {
        commit('SET_USER_INFO', req.ctx.session.userInfo);
    } else {
        commit('SET_USER_INFO', null);
    }
}
export async function uploadFile({ commit }, params) {
    return await this.$axios.post(Api.uploadfile, params, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
    });
}
export async function getCitys({ commit }, params) {
    params = {
        levelType: 1,
        ...params
    }
    let commitType = {
        1: 'SET_PROVINCE',
        2: 'SET_CITYS',
        3: 'SET_DISTRICT'
    };
    let { data } = await this.$axios.post(Api.getCitys, params);
    if (params.levelType < 3) {
        commit(commitType[2], []);
        commit(commitType[3], []);
    }
    commit(commitType[params.levelType], data || []);
}
// 更新用户资料
export async function userUpdateInfo({ commit }, params) {
    let result = await this.$axios.post(Api.updateInfo, params);
    return result;
}

